<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\CreateReturnLogRequest;
use App\Http\Requests\UpdateReturnLogRequest;
use App\Models\ReturnLog;
use App\Repositories\ReturnLogRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class ReturnLogController extends AppBaseController
{
    /** @var  ReturnLogRepository */
    private $returnLogRepository;

    public function __construct(ReturnLogRepository $returnLogRepo)
    {
        $this->returnLogRepository = $returnLogRepo;
    }

    /**
     * Display a listing of the ReturnLog.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->returnLogRepository->pushCriteria(new RequestCriteria($request));
        $returnLogs = ReturnLog::orderBy('id','desc')->paginate(20);

        return view('return_logs.index')
            ->with('returnLogs', $returnLogs);
    }

    /**
     * Show the form for creating a new ReturnLog.
     *
     * @return Response
     */
    public function create()
    {
        return view('return_logs.create');
    }

    /**
     * Store a newly created ReturnLog in storage.
     *
     * @param CreateReturnLogRequest $request
     *
     * @return Response
     */
    public function store(CreateReturnLogRequest $request)
    {
        $input = $request->all();

        $returnLog = $this->returnLogRepository->create($input);

        Flash::success('Return Log saved successfully.');

        return redirect(route('returnLogs.index'));
    }

    /**
     * Display the specified ReturnLog.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $returnLog = $this->returnLogRepository->findWithoutFail($id);

        if (empty($returnLog)) {
            Flash::error('Return Log not found');

            return redirect(route('returnLogs.index'));
        }

        return view('return_logs.show')->with('returnLog', $returnLog);
    }

    /**
     * Show the form for editing the specified ReturnLog.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $returnLog = $this->returnLogRepository->findWithoutFail($id);

        if (empty($returnLog)) {
            Flash::error('Return Log not found');

            return redirect(route('returnLogs.index'));
        }

        return view('return_logs.edit')->with('returnLog', $returnLog);
    }

    /**
     * Update the specified ReturnLog in storage.
     *
     * @param  int              $id
     * @param UpdateReturnLogRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateReturnLogRequest $request)
    {
        $returnLog = $this->returnLogRepository->findWithoutFail($id);

        if (empty($returnLog)) {
            Flash::error('Return Log not found');

            return redirect(route('returnLogs.index'));
        }

        $returnLog = $this->returnLogRepository->update($request->all(), $id);

        Flash::success('Return Log updated successfully.');

        return redirect(route('returnLogs.index'));
    }

    /**
     * Remove the specified ReturnLog from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $returnLog = $this->returnLogRepository->findWithoutFail($id);

        if (empty($returnLog)) {
            Flash::error('Return Log not found');

            return redirect(route('returnLogs.index'));
        }

        $this->returnLogRepository->delete($id);

        Flash::success('Return Log deleted successfully.');

        return redirect(route('returnLogs.index'));
    }
}
